package com.itheima.test.TCP.threadpool;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Service {//线程池优化服务器接受文件,并保存到服务器,服务器一直开启,可以同时接受文件上传,线程池优化,UUID优化

    public static void main(String[] args) throws IOException {
        //创建网络中的流
        ServerSocket serverSocket = new ServerSocket(1000);
        //创建线程池
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                5,
                10,
                10,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
        while (true) {//服务器不停循环
            Socket socket = serverSocket.accept();
            MyRunnable mr = new MyRunnable(socket);
            pool.submit(mr);
        }
    }
}
